<script type="text/javascript">
	//表格查询  
	function reloadModeler() {
		var params = modeler_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		modeler_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		modeler_list.datagrid('unselectAll');
		modeler_list.datagrid('uncheckAll');
	}
	
	function clearModelerSearch() {
		setGridSearchParams('modeler_list','modelerSearchForm',true,reloadModeler);
	}
	
	//根据条件查询
	function modelerSearch() {
		setGridSearchParams('modeler_list','modelerSearchForm',false,reloadModeler);
	}
	var diag = null;
	function addModeler(id) {
// 	 	window.mainpage.clickMenuAddModelTab(new Date().getTime(),'新增流程模型','','modeler.do?modelerOpen','icon-save',false,true);
	 	url = "modeler.do?modelerOpen";
	 	if(id != "")
	 	{
	 		url = "modeler.do?modelerOpen&id=" + id;
	 	}
	 	diag = createFromWindowOptions({
			title:"新增流程模型",
			maximizable:true,
			width:document.body.clientWidth,
			height:document.body.clientHeight,
			href:url,
			callback:function(d) {
			},
			enableCloseButton : false,
			closable : false,
			enableSaveButton:false
		});
	}
	
	function deleteModeler() {
		var rows = modeler_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('modeler.do?modelerRemove',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadModeler();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	//操作按钮触发
	function operationsLookModele(id) {
	debugger;
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = modeler_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) 
		{
			$.messager.confirm('询问','你确认要发布吗?',function(r){
	            if (r){
	                $.post('modeler.do?modelerDeploy',{id:id},function(result){
	                    if (result.success){
	                    	reloadModeler();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
		} 
		else 
		{
			showMsg('请选择查看记录.');
		}
	}
	
	function operationsDeleteModele(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = modeler_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			$.messager.confirm('询问', '你确认要删除吗?', function(r) {
				if (r) {
					$.post('modeler.do?modelerRemove', {
						ids : id
					}, function(result) {
						if (result.success) {
							reloadModeler(); 
						}
						showMsg(result.msg);
					}, 'json');
				}
			});
		} else {
			showMsg("请选择操作记录.");
		}
	}

	function operationsEditModele(id) {
		addModeler(id);
	}
</script>
<#assign operations =
"[
\{shiro:'bmp:modeler:edit',onClick:'operationsEditModele',src:'static/jmax/images/notes/note_edit.png',title:'编辑'},
\{shiro:'bmp:modeler:deploy',onClick:'operationsLookModele',src:'static/jmax/images/notes/note.png',title:'发布'},
\{shiro:'bmp:modeler:delete',onClick:'operationsDeleteModele',src:'static/jmax/images/notes/note_delete.png',title:'删除'}
]"/>

<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		<@eu.datagrid id="modeler_list" toolbar="#modelerList_search"
		idField="id" operations="${operations!}" url="modeler.do?modelerList"
		rownumbers="true" onDblClickRow="onDblClickModeleRow(rowIndex,
		rowData)" item="com.xdtech.oa.bpm.vo.ModelerItem"/>

		<div id="modelerList_search">
			<div style="margin-bottom:5px;padding-left:5px;margin-top: 5px;">
				<form id="modelerSearchForm">
					<!-- 防止form表单里只有一个text元素时候，按enter键自动提交问题 -->
					<input style="display:none" />
					<table>
						<tr>
						<td class="tbLabel">名称：</td>
							<td><input class="easyui-validatebox textbox" name="name" style="width: 150px" />
						</td>
						<td rowspan="2">
							<@eu.linkbutton showName="查询" iconCls="icon-search" onclick="modelerSearch()"/>
 					 		<@eu.linkbutton showName="清空" iconCls="icon-clear" onclick="clearModelerSearch()"/>
					 	</td>
						</tr>
					</table>
				</form>

			</div>
			<div id="modeler_toolbar" style="height: auto">
				<@eu.linkbutton showName="新增" shiro="bmp:modeler:add"
				iconCls="icon-add" onclick="addModeler('')"/> <@eu.linkbutton
				showName="删除" shiro="bmp:modeler:delete" iconCls="icon-remove"
				onclick="deleteModeler()"/>  <@eu.linkbutton showName="刷新"
				shiro="bmp:modeler:refresh" iconCls="icon-reload"
				onclick="reloadModeler()"/></div>
		</div>
	</div>
</div>